package com.boc.langxiang.ui.activity.me;

import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.os.SystemClock;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;

import com.boc.langxiang.App;
import com.boc.langxiang.Constant;
import com.boc.langxiang.R;
import com.boc.langxiang.contract.me.OrdersDetailContract;
import com.boc.langxiang.entity.events.OrdersEvent;
import com.boc.langxiang.entity.response.OrderinfoBean;
import com.boc.langxiang.entity.response.OrdersDetailReturnProductContent;
import com.boc.langxiang.entity.response.OrdersDetailWaitDeliveryContent;
import com.boc.langxiang.entity.response.OrdersDetailWaitPayContent;
import com.boc.langxiang.entity.response.OrdersDetailWaitReceiveContent;
import com.boc.langxiang.entity.response.ProductBean;
import com.boc.langxiang.entity.response.ProductReturnProductDetailBean;
import com.boc.langxiang.entity.response.ReturninfoBean;
import com.boc.langxiang.presenter.me.OrdersDetailPresenter;
import com.boc.langxiang.ui.adapter.me.OrdersDetailRVAdapter;
import com.boc.langxiang.ui.adapter.me.OrdersDetailReturnProductRVAdapter;
import com.boc.langxiang.ui.dialog.OrderMePayDialog;
import com.boc.langxiang.ui.view.SongTextView;
import com.boc.langxiang.util.StringUtil;
import com.boc.langxiang.util.T;
import com.jakewharton.rxbinding.view.RxView;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

import butterknife.BindView;
import butterknife.ButterKnife;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;

/**
 * 订单详情
 */
public class OrdersDetailActivity extends MeBaseToolBarActivity implements OrdersDetailContract.View {

    @BindView(R.id.btn_me_orders_detail_leftbtn)
    Button btnMeOrdersDetailLeftbtn;
    @BindView(R.id.btn_me_orders_deetail_rightbtn)
    Button btnMeOrdersDeetailRightbtn;
    @BindView(R.id.linlayout_me_orders_bottom)
    LinearLayout linlayoutMeOrdersBottom;

    private TextView tvMeWdDetailName;
    private TextView tvMeWdDetailPhone;
    private TextView tvMeWdDetailAddress;
    private TextView tvMeWdDetailTime;
    @BindView(R.id.rv_me_orders_wd_detail)
    RecyclerView rvMeOrdersWdDetail;
    private OrdersDetailPresenter mPresneter;
    private List<ProductBean> mList;
    private List<ProductReturnProductDetailBean> mReturnList;
    private OrdersDetailRVAdapter mAdapter;
    private OrdersDetailReturnProductRVAdapter mReturnAdapter;
    private String mProductId;
    private View mView;
    private TextView tvMeOrdersDwdNumbers;
    private TextView tvMeOrdersDwdStatus;
    private int mType;
    private TextView tvMeDetailReturnNumbers;
    private TextView tvMeDetailReturnMoney;
    private String mTotalPrice;
    private TextView tvMeLogisticalNumbers;
    private SongTextView stvMeOrdersTitle;
    private StringBuffer mSb;
    private long lastTime = 0l;
    private long currentTime;
    private PopupWindow mCancelPop;
    private String mWaitPayOrderId;
    private OrdersDetailContract.View mContractView;
    private String mWaitDeliveryOrderId;
    private boolean mIsGoToDetail;
    private PopupWindow mReceivePop;
    private TextView mReturnOrderStatus;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_orders_wait_delivery_detail);
        ButterKnife.bind(this);
        setToolBarTitle("订单详情");
        mContractView = this;
        mSb = new StringBuffer();
        mProductId = getIntent().getExtras().getString(Constant.ME_PRODUCT_ID);
        mType = getIntent().getExtras().getInt(Constant.ME_PRODUCT_TYPE);
        mTotalPrice = getIntent().getExtras().getString(Constant.ME_PRODUCT_TOTALPRICE);
        mPresneter = new OrdersDetailPresenter(this);
        rvMeOrdersWdDetail.setHasFixedSize(true);
        rvMeOrdersWdDetail.setLayoutManager(new LinearLayoutManager(mContext));
        initAdapter();
        initBottomButtonStyle();
    }


    private void initBottomButtonStyle() {
        switch (mType) {
            case Constant.ME_PRODUCT_TYPE_DEFAULT: //默认
                mPresneter.toPayOrdersInfo(mProductId);
                linlayoutMeOrdersBottom.setVisibility(View.VISIBLE);
                btnMeOrdersDetailLeftbtn.setVisibility(View.VISIBLE);
                btnMeOrdersDeetailRightbtn.setVisibility(View.VISIBLE);
                btnMeOrdersDeetailRightbtn.setText("付款");
                btnMeOrdersDetailLeftbtn.setText("取消订单");
                stvMeOrdersTitle.setText("等待买家付款");
                btnMeOrdersDetailLeftbtn.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        currentTime = SystemClock.uptimeMillis();
                        if (currentTime - lastTime > 1500l) {
                            View cancelView = View.inflate(OrdersDetailActivity.this, R.layout.popwindow_orders_cancel, null);
                            mCancelPop = new PopupWindow(cancelView, (int) (App.getInstance().getResources().getDisplayMetrics().widthPixels * 0.8), LinearLayout.LayoutParams.WRAP_CONTENT);
                            mCancelPop.setAnimationStyle(R.style.me_pop_anim_center_style);
                            mCancelPop.setFocusable(true);
                            mCancelPop.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
                            mCancelPop.setOutsideTouchable(true);
                            mCancelPop.setOnDismissListener(new PopupWindow.OnDismissListener() {
                                @Override
                                public void onDismiss() {
                                    setAlpha(1f);
                                }
                            });
                            showPopupWindow(cancelView, mCancelPop);
                            setAlpha(0.5f);
                            RxView.clicks(mCancelPop.getContentView().findViewById(R.id.atv_me_orders_sure)).throttleFirst(2000, TimeUnit.MILLISECONDS).observeOn(AndroidSchedulers.mainThread())
                                    .subscribe(new Action1<Void>() {
                                        @Override
                                        public void call(Void aVoid) {
                                            setAlpha(1f);
                                            cancelPopupWindow();
                                            mPresneter.cancelOrders(mProductId);
                                        }
                                    });
                            RxView.clicks(mCancelPop.getContentView().findViewById(R.id.atv_me_orders_giveup)).throttleFirst(2000, TimeUnit.MILLISECONDS).observeOn(AndroidSchedulers.mainThread())
                                    .subscribe(new Action1<Void>() {
                                        @Override
                                        public void call(Void aVoid) {
                                            setAlpha(1f);
                                            cancelPopupWindow();
                                        }
                                    });
                            lastTime = currentTime;
                        }
                    }
                });
                btnMeOrdersDeetailRightbtn.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        OrderMePayDialog orderPayDialog = new OrderMePayDialog(mContext, mContractView, mWaitPayOrderId, mTotalPrice);
                        orderPayDialog.show();
                        Window win = orderPayDialog.getWindow();
                        win.setWindowAnimations(R.style.me_pop_anim_bottom_style);
                        win.getDecorView().setPadding(0, 0, 0, 0);
                        WindowManager.LayoutParams lp = win.getAttributes();
                        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
                        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
                        win.setAttributes(lp);
                    }
                });

                break;
            case Constant.ME_PRODUCT_TYPE_CANCEL: //取消
                linlayoutMeOrdersBottom.setVisibility(View.GONE);
                btnMeOrdersDetailLeftbtn.setVisibility(View.GONE);
                btnMeOrdersDeetailRightbtn.setVisibility(View.GONE);
                stvMeOrdersTitle.setText("订单已取消");
                break;
            case Constant.ME_PRODUCT_TYPE_WAITDELIVERY: //待发货
                mPresneter.toSendOrdersInfo(mProductId);
                linlayoutMeOrdersBottom.setVisibility(View.VISIBLE);
                btnMeOrdersDetailLeftbtn.setVisibility(View.GONE);
                btnMeOrdersDeetailRightbtn.setVisibility(View.VISIBLE);
                btnMeOrdersDeetailRightbtn.setText("申请退款");
                stvMeOrdersTitle.setText("等待卖家发货");
                btnMeOrdersDeetailRightbtn.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(OrdersDetailActivity.this, OrdersApplyRefundActivity.class);
                        intent.putExtra(Constant.ME_PRODUCT_TYPE_RETURN_PRICE, mTotalPrice);
                        intent.putExtra(Constant.ME_PRODUCT_TYPE_RETURN_ID, mWaitDeliveryOrderId);
                        startActivity(intent);
                    }
                });
                break;
            case Constant.ME_PRODUCT_TYPE_HASDELIVERY://已发货
                mPresneter.toReceiptOrdersInfo(mProductId);
                linlayoutMeOrdersBottom.setVisibility(View.VISIBLE);
                btnMeOrdersDetailLeftbtn.setVisibility(View.VISIBLE);
                btnMeOrdersDeetailRightbtn.setVisibility(View.VISIBLE);
                btnMeOrdersDeetailRightbtn.setText("确认收货");
                stvMeOrdersTitle.setText("卖家已发货");
                btnMeOrdersDetailLeftbtn.setText("申请退款");
                btnMeOrdersDeetailRightbtn.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        currentTime = SystemClock.uptimeMillis();
                        if (currentTime - lastTime > 1500l) {
                            View receiveView = View.inflate(mContext, R.layout.popwindow_orders_receive, null);
                            mReceivePop = new PopupWindow(receiveView, (int) (App.getInstance().getResources().getDisplayMetrics().widthPixels * 0.8), LinearLayout.LayoutParams.WRAP_CONTENT);
                            mReceivePop.setAnimationStyle(R.style.me_pop_anim_center_style);
                            mReceivePop.setFocusable(true);
                            mReceivePop.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
                            mReceivePop.setOutsideTouchable(true);
                            mReceivePop.setOnDismissListener(new PopupWindow.OnDismissListener() {
                                @Override
                                public void onDismiss() {
                                    setAlpha(1f);
                                }
                            });
                            showPopupWindow(receiveView, mReceivePop);
                            setAlpha(0.5f);
                            RxView.clicks(mReceivePop.getContentView().findViewById(R.id.atv_me_orders_rec_sure)).throttleFirst(2000, TimeUnit.MILLISECONDS).observeOn(AndroidSchedulers.mainThread())
                                    .subscribe(new Action1<Void>() {
                                        @Override
                                        public void call(Void aVoid) {
                                            setAlpha(1f);
                                            cancelPopupWindow();
                                            mPresneter.confirmReceipt(mProductId);
                                            EventBus.getDefault().post(new OrdersEvent());

                                        }
                                    });
                            RxView.clicks(mReceivePop.getContentView().findViewById(R.id.atv_me_orders_rec_cel)).throttleFirst(2000, TimeUnit.MILLISECONDS).observeOn(AndroidSchedulers.mainThread())
                                    .subscribe(new Action1<Void>() {
                                        @Override
                                        public void call(Void aVoid) {
                                            setAlpha(1f);
                                            cancelPopupWindow();
                                        }
                                    });
                            lastTime = currentTime;
                        }
                    }
                });

                btnMeOrdersDetailLeftbtn.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(OrdersDetailActivity.this, OrdersApplyRefundActivity.class);
                        intent.putExtra(Constant.ME_PRODUCT_TYPE_RETURN_PRICE, mTotalPrice);
                        intent.putExtra(Constant.ME_PRODUCT_TYPE_RETURN_ID, mWaitDeliveryOrderId);
                        startActivity(intent);
                    }
                });

                break;
            case Constant.ME_PRODUCT_TYPE_RECEIVEPRODUCT://已收货（完成）
                mPresneter.toReceiptOrdersInfo(mProductId);
                linlayoutMeOrdersBottom.setVisibility(View.VISIBLE);
                btnMeOrdersDetailLeftbtn.setVisibility(View.GONE);
                btnMeOrdersDeetailRightbtn.setVisibility(View.VISIBLE);
                btnMeOrdersDeetailRightbtn.setText("申请退款");
                btnMeOrdersDeetailRightbtn.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(OrdersDetailActivity.this, OrdersApplyRefundActivity.class);
                        intent.putExtra(Constant.ME_PRODUCT_TYPE_RETURN_PRICE, mTotalPrice);
                        intent.putExtra(Constant.ME_PRODUCT_TYPE_RETURN_ID, mWaitDeliveryOrderId);
                        startActivity(intent);
                    }
                });
                stvMeOrdersTitle.setText("订单完成");
                break;
            case Constant.ME_PRODUCT_TYPE_RETURN://申请退款退货
                mPresneter.returnOrdersInfo(mProductId);
                linlayoutMeOrdersBottom.setVisibility(View.GONE);
                mReturnOrderStatus.setText("退货退款中");
                break;
            case Constant.ME_PRODUCT_TYPE_RETURNFINISH://退款退货完成
                mPresneter.returnOrdersInfo(mProductId);
                linlayoutMeOrdersBottom.setVisibility(View.GONE);
                mReturnOrderStatus.setText("退货退款完成");
                break;
            case Constant.ME_PRODUCT_TYPE_RETURNFAILD://退款退货失败
                mPresneter.returnOrdersInfo(mProductId);
                linlayoutMeOrdersBottom.setVisibility(View.GONE);
                mReturnOrderStatus.setText("退货退款失败");
                break;
        }
    }

    private void cancelPopupWindow() {

        if (mCancelPop != null) {
            if (mCancelPop.isShowing()) {
                mCancelPop.dismiss();
            }
        }
        if (mReceivePop != null) {
            if (mReceivePop.isShowing()) {
                mReceivePop.dismiss();
            }
        }
    }

    private void showPopupWindow(View view, PopupWindow mCancelPop) {
        mCancelPop.showAtLocation(view, Gravity.CENTER, 0, 0);
    }

    private void setAlpha(float value) {
        WindowManager.LayoutParams attributes = getWindow().getAttributes();
        attributes.alpha = value;
        getWindow().setAttributes(attributes);
    }

    private void initAdapter() {
//        if (mType != Constant.ME_PRODUCT_TYPE_RETURN) {
//            mList = new ArrayList<>();
//            mAdapter = new OrdersDetailRVAdapter(mContext, mList);
//            mAdapter.setTotalPrice(mTotalPrice);
//            mView = LayoutInflater.from(mContext).inflate(R.layout.header_detail_wd, null, false);
//            tvMeWdDetailName = (TextView) mView.findViewById(R.id.tv_me_wd_detail_name);
//            tvMeWdDetailPhone = (TextView) mView.findViewById(R.id.tv_me_wd_detail_phone);
//            tvMeWdDetailAddress = (TextView) mView.findViewById(R.id.tv_me_wd_detail_address);
//            tvMeWdDetailTime = (TextView) mView.findViewById(R.id.tv_me_wd_detail_time);
//            tvMeOrdersDwdNumbers = ((TextView) mView.findViewById(R.id.tv_me_orders_dwd_numbers));
//            tvMeOrdersDwdStatus = ((TextView) mView.findViewById(R.id.tv_me_orders_dwd_status));
//            tvMeLogisticalNumbers = ((TextView) mView.findViewById(R.id.tv_me_logistical_numbers));
//            stvMeOrdersTitle = ((SongTextView) mView.findViewById(R.id.stv_me_orders_title));
//            View viewMeDivider = mView.findViewById(R.id.view_me_divider);
//            if (mType == Constant.ME_PRODUCT_TYPE_HASDELIVERY) {
//                tvMeLogisticalNumbers.setVisibility(View.VISIBLE);
//                viewMeDivider.setVisibility(View.VISIBLE);
//            } else {
//                tvMeLogisticalNumbers.setVisibility(View.GONE);
//                viewMeDivider.setVisibility(View.GONE);
//            }
//            mAdapter.addHeaderView(mView);
//            rvMeOrdersWdDetail.setAdapter(mAdapter);
//        } else 
        if (mType == Constant.ME_PRODUCT_TYPE_RETURN || mType == Constant.ME_PRODUCT_TYPE_RETURNFINISH || mType == Constant.ME_PRODUCT_TYPE_RETURNFAILD) {
            mReturnList = new ArrayList<>();
            mReturnAdapter = new OrdersDetailReturnProductRVAdapter(mContext, mReturnList);
            mReturnAdapter.setTotalPrice(mTotalPrice);
            mView = LayoutInflater.from(mContext).inflate(R.layout.header_detail_returnproduct, null, false);
            tvMeWdDetailTime = (TextView) mView.findViewById(R.id.tv_me_wd_detail_time);
            mReturnOrderStatus = (TextView) mView.findViewById(R.id.order_status);
            tvMeOrdersDwdNumbers = ((TextView) mView.findViewById(R.id.tv_me_orders_dwd_numbers));
            tvMeOrdersDwdStatus = ((TextView) mView.findViewById(R.id.tv_me_orders_dwd_status));
            tvMeDetailReturnNumbers = ((TextView) mView.findViewById(R.id.tv_me_detail_returnnumbers));
            tvMeDetailReturnMoney = ((TextView) mView.findViewById(R.id.tv_me_detail_returnmoney));
            mReturnAdapter.addHeaderView(mView);
            rvMeOrdersWdDetail.setAdapter(mReturnAdapter);
        } else {
            mList = new ArrayList<>();
            mAdapter = new OrdersDetailRVAdapter(mContext, mList);
            mAdapter.setTotalPrice(mTotalPrice);
            mView = LayoutInflater.from(mContext).inflate(R.layout.header_detail_wd, null, false);
            tvMeWdDetailName = (TextView) mView.findViewById(R.id.tv_me_wd_detail_name);
            tvMeWdDetailPhone = (TextView) mView.findViewById(R.id.tv_me_wd_detail_phone);
            tvMeWdDetailAddress = (TextView) mView.findViewById(R.id.tv_me_wd_detail_address);
            tvMeWdDetailTime = (TextView) mView.findViewById(R.id.tv_me_wd_detail_time);
            tvMeOrdersDwdNumbers = ((TextView) mView.findViewById(R.id.tv_me_orders_dwd_numbers));
            tvMeOrdersDwdStatus = ((TextView) mView.findViewById(R.id.tv_me_orders_dwd_status));
            tvMeLogisticalNumbers = ((TextView) mView.findViewById(R.id.tv_me_logistical_numbers));
            stvMeOrdersTitle = ((SongTextView) mView.findViewById(R.id.stv_me_orders_title));
            View viewMeDivider = mView.findViewById(R.id.view_me_divider);
            if (mType == Constant.ME_PRODUCT_TYPE_HASDELIVERY || mType == Constant.ME_PRODUCT_TYPE_RECEIVEPRODUCT) {
                tvMeLogisticalNumbers.setVisibility(View.VISIBLE);
                viewMeDivider.setVisibility(View.VISIBLE);
            } else {
                tvMeLogisticalNumbers.setVisibility(View.GONE);
                viewMeDivider.setVisibility(View.GONE);
            }
            mAdapter.addHeaderView(mView);
            rvMeOrdersWdDetail.setAdapter(mAdapter);
        }
    }


    @Override
    public void showLoading() {
        showProgressDialog();
    }

    @Override
    public void hideLoading() {
        hideDialog();
    }

    @Override
    public void onError(String code, String msg) {
        if (mCancelPop != null) {
            if (mCancelPop.isShowing()) {
                mCancelPop.dismiss();
            }
        }
        T.showShort(mContext, msg);
    }

    /**
     * 待付款详情信息
     *
     * @param content
     */
    @Override
    public void getPayOrdersInfo(OrdersDetailWaitPayContent content) {
        if (mSb == null) {
            mSb = new StringBuffer();
        }
        mSb.setLength(0);
        OrderinfoBean orderinfo = content.getOrderinfo();
        mWaitPayOrderId = orderinfo.getOrderid();
        String province = orderinfo.getProvince();
        String city = orderinfo.getCity();
        String district = orderinfo.getDistrict();
        String address = orderinfo.getAddress();
        mSb.append(StringUtil.isEmpty(province) ? "" : province);
        mSb.append(StringUtil.isEmpty(city) ? "" : city);
        mSb.append(StringUtil.isEmpty(district) ? "" : district);
        mSb.append(StringUtil.isEmpty(address) ? "" : address);
        tvMeWdDetailName.setText(StringUtil.isEmpty(orderinfo.getUsername()) ? "" : orderinfo.getUsername());
        tvMeWdDetailPhone.setText(StringUtil.isEmpty(orderinfo.getPhone()) ? "" : orderinfo.getPhone());
        tvMeWdDetailAddress.setText(StringUtil.isEmpty(mSb.toString()) ? "" : mSb.toString());
        tvMeOrdersDwdNumbers.setText(StringUtil.isEmpty(orderinfo.getOrderid()) ? "" : orderinfo.getOrderid());
        tvMeOrdersDwdStatus.setText(getOrdersStatus());
        String orderinfoTimeline = orderinfo.getTimeline();
        tvMeWdDetailTime.setText("订单时间：" + (StringUtil.isEmpty(orderinfoTimeline) ? "" : orderinfoTimeline));
        mList = content.getProduct();
        mAdapter.setTotalNum(mList.size());
        mAdapter.setNewData(mList);


    }

    /**
     * 待发货详情信息
     *
     * @param content
     */
    @Override
    public void getSendOrdersInfo(OrdersDetailWaitDeliveryContent content) {
        if (mSb == null) {
            mSb = new StringBuffer();
        }
        mSb.setLength(0);
        OrderinfoBean orderinfo = content.getOrderinfo();
        String province = orderinfo.getProvince();
        String city = orderinfo.getCity();
        String district = orderinfo.getDistrict();
        String address = orderinfo.getAddress();
        mWaitDeliveryOrderId = orderinfo.getOrderid();
        mSb.append(StringUtil.isEmpty(province) ? "" : province);
        mSb.append(StringUtil.isEmpty(city) ? "" : city);
        mSb.append(StringUtil.isEmpty(district) ? "" : district);
        mSb.append(StringUtil.isEmpty(address) ? "" : address);
        tvMeWdDetailName.setText(StringUtil.isEmpty(orderinfo.getUsername()) ? "" : orderinfo.getUsername());
        tvMeWdDetailPhone.setText(StringUtil.isEmpty(orderinfo.getPhone()) ? "" : orderinfo.getPhone());
        tvMeWdDetailAddress.setText(StringUtil.isEmpty(mSb.toString()) ? "" : mSb.toString());
        tvMeOrdersDwdNumbers.setText(StringUtil.isEmpty(orderinfo.getOrderid()) ? "" : orderinfo.getOrderid());
        tvMeOrdersDwdStatus.setText(getOrdersStatus());
        String orderinfoTimeline = orderinfo.getTimeline();
        tvMeWdDetailTime.setText("订单时间：" + (StringUtil.isEmpty(orderinfoTimeline) ? "" : orderinfoTimeline));
        mList = content.getProduct();
        mAdapter.setTotalNum(mList.size());
        mAdapter.setNewData(mList);
    }


    @Override
    public void cancelOrdersSuccess() {
        Toast.makeText(App.getInstance(), "订单取消成功", Toast.LENGTH_SHORT).show();
        EventBus.getDefault().post(new OrdersEvent());
        finish();
    }

    @Override
    public void onPaySuccess() {
        Toast.makeText(App.getInstance(), "支付成功", Toast.LENGTH_SHORT).show();
        finish();
    }

    @Override
    public void conFirmReceiptSuccess() {
        Toast.makeText(App.getInstance(), "收货成功", Toast.LENGTH_SHORT).show();
        finish();
    }

    /**
     * 待收货详情信息
     *
     * @param content
     */
    @Override
    public void getReceiptOrdersInfo(OrdersDetailWaitReceiveContent content) {
        if (mSb == null) {
            mSb = new StringBuffer();
        }
        mSb.setLength(0);
        OrderinfoBean orderinfo = content.getOrderinfo();
        String province = orderinfo.getProvince();
        String city = orderinfo.getCity();
        String district = orderinfo.getDistrict();
        String address = orderinfo.getAddress();
        mSb.append(StringUtil.isEmpty(province) ? "" : province);
        mSb.append(StringUtil.isEmpty(city) ? "" : city);
        mSb.append(StringUtil.isEmpty(district) ? "" : district);
        mSb.append(StringUtil.isEmpty(address) ? "" : address);
        mWaitDeliveryOrderId = orderinfo.getOrderid();
        tvMeWdDetailName.setText(StringUtil.isEmpty(orderinfo.getUsername()) ? "" : orderinfo.getUsername());
        tvMeWdDetailPhone.setText(StringUtil.isEmpty(orderinfo.getPhone()) ? "" : orderinfo.getPhone());
        tvMeWdDetailAddress.setText(StringUtil.isEmpty(mSb.toString()) ? "" : mSb.toString());
        tvMeOrdersDwdNumbers.setText(StringUtil.isEmpty(orderinfo.getOrderid()) ? "" : orderinfo.getOrderid());
        tvMeOrdersDwdStatus.setText(getOrdersStatus());
        tvMeLogisticalNumbers.setText("物流单号:" + (StringUtil.isEmpty(orderinfo.getTransport_id()) ? "" : orderinfo.getTransport_id()));
        String orderinfoTimeline = orderinfo.getTimeline();
        tvMeWdDetailTime.setText("订单时间：" + (StringUtil.isEmpty(orderinfoTimeline) ? "" : orderinfoTimeline));
        mList = content.getProduct();
        mAdapter.setTotalNum(mList.size());
        mAdapter.setNewData(mList);
    }

    /**
     * 退货详情信息
     *
     * @param content
     */
    @Override
    public void getReturnOrdersInfo(OrdersDetailReturnProductContent content) {
        ReturninfoBean returninfo = content.getReturninfo();
        tvMeDetailReturnNumbers.setText(returninfo.getReturnid());
        tvMeDetailReturnMoney.setText(returninfo.getPrice());
        String timeline = returninfo.getTimeline();
        tvMeWdDetailTime.setText(StringUtil.isEmpty(timeline) ? "" : timeline);
        tvMeOrdersDwdNumbers.setText(StringUtil.isEmpty(returninfo.getOrderid()) ? "" : returninfo.getOrderid());
        tvMeOrdersDwdStatus.setText(getOrdersStatus());
        List<ProductReturnProductDetailBean> product = content.getProduct();
        mReturnAdapter.setTotalNum(product.size());
        mReturnAdapter.setNewData(product);
    }

    private CharSequence getOrdersStatus() {
        switch (mType) {
            case Constant.ME_PRODUCT_TYPE_DEFAULT: //默认
                return "待付款";
            case Constant.ME_PRODUCT_TYPE_CANCEL: //取消
                return "订单取消";
            case Constant.ME_PRODUCT_TYPE_WAITDELIVERY: //待发货
                return "待发货";
            case Constant.ME_PRODUCT_TYPE_HASDELIVERY://已发货
                return "已发货";
            case Constant.ME_PRODUCT_TYPE_RECEIVEPRODUCT://已收货（完成）
                return "订单完成";
            case Constant.ME_PRODUCT_TYPE_RETURN://申请退款退货
                return "申请退款";
            case Constant.ME_PRODUCT_TYPE_RETURNFINISH://退款退货完成
                return "退款退货完成";
            case Constant.ME_PRODUCT_TYPE_RETURNFAILD://退款退货完成
                return "退款退货失败";
            default:
                return "无效订单";
        }

    }

}
